﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="news_search_tree.aspx.cs" Inherits="Ccit.OA.NewsCenter.news_search_tree" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<%@ Register Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="Microsoft.Web.UI.WebControls" TagPrefix="iewc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>信息中心-信息栏目树</title>
    <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>
    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jsonlib.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jcontrol.js" type="text/javascript"></script>
    <style type="text/css">
        .skin
        {
            border-right: buttonhighlight 2px outset;
            border-top: buttonhighlight 2px outset;
            font-size: 9pt;
            visibility: hidden;
            border-left: buttonhighlight 2px outset;
            width: 100px;
            cursor: default;
            border-bottom: buttonhighlight 2px outset;
            font-family: Arial, Helvetica, sans-serif;
            position: absolute;
            background-color: menu;
            text-align: left;
        }
        .menuitems
        {
            padding-right: 5px;
            padding-left: 5px;
            padding-top: 5px;
            padding-bottom: 5px;
        }
    </style>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">
    <input type="hidden" id="_hidTabId" runat="server" />
    <input type="hidden" id="_hidPurColIds" runat="server" />
    <input type="hidden" id="_hidWhereClause" runat="server" />
    <!--信息类别-->
    <input type="hidden" id="_hidType" value="" runat="server" /> 
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>   
    
    <iewc:TreeView ID="tvColumn" runat="server"></iewc:TreeView>
    
    <script type="text/javascript" language="javascript">  
     var menuskin = "skin";
		var node = null;
		var menuname = "root";		
		
		function hideMenu() 
		{		    
			var obj = document.getElementById(menuname);
			if (null != obj && typeof(obj) != "undefined")
				document.getElementById(menuname).style.visibility = "hidden";
		}
       function tvColumn.onexpand()
		{	
		    /* Step 1：find current click TreeNode */	    
		    var nodeIndex = event.treeNodeIndex;	
		   // alert(nodeIndex);		
			if (typeof(nodeIndex) == "undefined"){			
				node = null;
				return false;
			}
			
			tvColumn.selectedNodeIndex = nodeIndex;
			node = tvColumn.getTreeNode(nodeIndex);
						
			/* Step 2: get asset type id,and get all child types */			
			var vNodeId = node.getAttribute("ID");
			var vNodeIdArray = vNodeId.split("_")
			var vColumnId = vNodeIdArray[0];
			var vLoadSign = vNodeIdArray[1];
			if(vColumnId != "0" && vLoadSign == "0") {
			    var oSubNodes = node.getChildren();
			    var oSubNode;
			    for(var i = oSubNodes.length - 1; i >= 0; i --) {
			        oSubNode = oSubNodes[i];
			        oSubNode.remove();
			    }
			   // var Type = document.getElementById("_hidType").value;
			    PageMethods.GetSubTypesByColumnId(vColumnId,nodeIndex,ClientCallBack);
			}
			hideMenu();
		}
		
		function tvColumn.oncollapse()
		{
			hideMenu();
		}
		
		function ClientCallBack(vExeResult){
		    var vNodeIdArray = vExeResult.split("_");
		    eval("var objResult="+vNodeIdArray[0]); 
		    var nodeIndex=vNodeIdArray[1];
            for(var i=0;i<objResult.length;i++)
            {
               var oResult=objResult[i];
               createSubTreeNodes(nodeIndex,oResult);
            }
		}
		
		function containFather(vPurColIds,colId)
        {
            var bFind = false;
            if(vPurColIds != "")
            {
                var ArrRange = vPurColIds.split(",");
                for(var i = 0;i < ArrRange.length;i++)
                {
                    if(colId == ArrRange[i])
                      bFind = true;
                }   
            }
            return bFind;
        }
		function containChild(vPurColIds,vChildColIds)
		{
		   var bFind = false;
		   if(vChildColIds != "")
		   {
		      if(vPurColIds != "")
		      {
		         var ArrRange = vPurColIds.split(",");
		         var ArrChild = vChildColIds.split(",");
                 for(var i = 0;i < ArrRange.length;i++)
                 {
                    for(var j = 0; j<ArrChild.length;j++)
                    {
                        if(ArrRange[i] == ArrChild[j])
                        {
                            bFind = true;
                        }
                    }
                 }    
		      }
		   }
		   return bFind;
		}
		
		//追加子节点
        function createSubTreeNodes(nodeIndex,oResult) { 
                
                 var vPurColIds = $get("_hidPurColIds").value;
                 
                 var fFind = containFather(vPurColIds,oResult.columnId);
                 
			     var node = $get("tvColumn").getTreeNode(nodeIndex); 
			     var vType = document.getElementById("_hidType").value;
			     var vPageParam = "Type="+vType+"&columnId=" + oResult.columnId+"";
	        	 var encodeParam = base64encode(vPageParam);
			     vNavigateUrl = "news_search_list.aspx?" + encodeParam;
			     
                 oSubNode = $get("tvColumn").createTreeNode();
		         oSubNode.setAttribute("ID",oResult.columnId + "_" + "0");
		         oSubNode.setAttribute("Text",oResult.columnName);
		         oSubNode.setAttribute("Type","root");
		         oSubNode.setAttribute("Target","iFrmList");
		         oSubNode.setAttribute("ImageUrl","../images/toolbar/filelogo.gif");
		         
		         if(fFind == true)
		         {
		            oSubNode.setAttribute("NavigateUrl",vNavigateUrl);
		         }
		         else
		         {
		            oSubNode.setAttribute("NavigateUrl","");
		            oSubNode.setAttribute("DefaultStyle","color:red;");
		         }
		         
		         var cFind = containChild(vPurColIds,oResult.ChildColIds);
		         
		         if(oResult.hasChild == "1" && cFind == true) {  //if contain sub node then add empty node
		           oEmptyNode = $get("tvColumn").createTreeNode();  
		           oSubNode.add(oEmptyNode); 
		         }
		         node.add(oSubNode);    
		        /* set node load sign = 1 */
		        var vNodeId = node.getAttribute("ID");
		        var vNodeIdArray = vNodeId.split("_")
			    oResult.columnId = vNodeIdArray[0];
			    node.setAttribute("ID",oResult.columnId  + "_" + "1");		    
        } 
		</script>
    </ccit:ActionForm>
</body>
</html>
